<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div>

    </div>
</body>
<script>
    /*
        1.创建一个新的对象
        2.该对象的__proto__指向构造函数的prototype
        3.将构造函数的作用域赋值给当前对象
        4.执行构造函数里边的方法，将属性值绑定给该新的对象
        5.返回新的对象
    */
    function Person(name,age){
        this.name = name;
        this.age = age;
        // return "DDDD"   没有事情
        // return {         //会出错
        //     ddd:'bbb'
        // }
    }
    Person.prototype.sayName = function () {
        console.log(this.name+''+this.age)
    };
    let persontop = new Person("夏洛",39)
    console.log(persontop)
    console.log(persontop.sayName())

    // class 
    class Person2{
        constructor(name,age){
            this.name = name
            this.age = age
        }
        sayName(){
            console.log(this.name+'---'+this.age)
        }
    }
    let ddperson = new Person2('马丽','65')
    console.log(ddperson)
    console.log(ddperson.sayName())
    </script>
</html>